package com.sptpc.learnspring.controller;

import com.sptpc.learnspring.global.response.GlobalResponse;
import com.sptpc.learnspring.model.Category;
import com.sptpc.learnspring.service.ICategoryService;
import com.sptpc.learnspring.vo.CategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    // 查询所有分类
    @GetMapping("/")
    public List<Category> getAllCategories() {
        // categoryService.reloadCategory();
        return categoryService.getAllCategories();
    }

    // 只查询分类信息
    @GetMapping("/{id}")
    public GlobalResponse getCategory(@PathVariable("id") Long id) {
        Category category = categoryService.getCategoryById(id);
        return GlobalResponse.success(category);
    }

    // 查询分类和其下面所有饮品
    @GetMapping("/{id}/a")
    public CategoryVO getCategoryWithDrinks(@PathVariable("id") Long id) {
        return categoryService.getCategoryWithDrinks(id);
    }
}
